package com.hikvision.open.app.widget

import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import com.hikvision.open.app.utils.ScreenUtils
import androidx.appcompat.app.AlertDialog
import hik.sdk.demo.R
import hik.sdk.demo.databinding.DialogPermissionBinding

class PermissionDialog(
    context: Context,
    private val message: String,
    private val rightText: String,
    private val permissions: MutableList<String>
) : AlertDialog(context, R.style.PermissionDialog) {

    private lateinit var viewBinding: DialogPermissionBinding

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        viewBinding = DialogPermissionBinding.inflate(LayoutInflater.from(context))
        setContentView(viewBinding.root)
        viewBinding.contentText.text = message
        viewBinding.rightButton.text = rightText
        window?.let {
            val param = it.attributes
            val width = if (ScreenUtils.isPortrait()) {
                (context.resources.displayMetrics.widthPixels * 0.8).toInt()
            } else {
                (context.resources.displayMetrics.heightPixels * 0.8).toInt()
            }
            val height = param.height
            it.setLayout(width, height)
        }
    }

    fun getPositiveButton(): View {
        return viewBinding.rightButton
    }

    fun getNegativeButton(): View? {
        return viewBinding.leftButton
    }

    fun getPermissionsToRequest(): MutableList<String> {
        return permissions
    }
}